package com.wushi.lenovo.asia5b.app_ui.wish.adapter;

import android.support.annotation.Nullable;
import android.support.constraint.ConstraintLayout;
import android.view.View;
import android.widget.ImageView;
import android.widget.TextView;

import com.chad.library.adapter.base.BaseQuickAdapter;
import com.chad.library.adapter.base.BaseViewHolder;
import com.mvp.images.WImageLoader;
import com.mvp.utils.ResString;
import com.wushi.lenovo.asia5b.R;
import com.wushi.lenovo.asia5b.app_model.wish.WishModel;
import com.wushi.lenovo.asia5b.app_ui.h5.GoodsDetailsActivity;

import java.util.List;

/**
 * Created by zhangyuncai on 2018/12/14.
 */
public class WishAdapter extends BaseQuickAdapter<WishModel, BaseViewHolder> {
    public WishAdapter(@Nullable List<WishModel> data) {
        super(R.layout.item_wish_adapter, data);
    }

    @Override
    protected void convert(BaseViewHolder helper, WishModel item) {
        ConstraintLayout cons_wish = helper.getView(R.id.cons_wish);
        cons_wish.setOnClickListener(v -> {
            GoodsDetailsActivity.startGoodsDetailsActivity(mContext, item.getProduct_id());
        });
//        SwipeLayout swipe_regist = helper.getView(R.id.swipe_regist);
//        swipe_regist.close();
        ImageView iv_wish_img = helper.getView(R.id.iv_wish_img);
        TextView tv_wish_name = helper.getView(R.id.tv_wish_name);
        TextView tv_wish_marketprice = helper.getView(R.id.tv_wish_marketprice);
        TextView tv_wish_percent = helper.getView(R.id.tv_wish_percent);
        TextView tv_wish_createtime = helper.getView(R.id.tv_wish_createtime);
        TextView tv_wish_price = helper.getView(R.id.tv_wish_price);
        //图片
        WImageLoader.displayImage(mContext, item.getImage(), iv_wish_img);
        //名称
        tv_wish_name.setText(item.getProduct_name());
        //市场价格
        tv_wish_marketprice.setText(item.getMarket_price());

        int percent = item.getDiscount_percentage();
        tv_wish_percent.setText(String.format("(-%d%%)", percent));
        tv_wish_percent.setVisibility(percent == 0 ? View.INVISIBLE : View.VISIBLE);
        tv_wish_marketprice.setVisibility(percent == 0 ? View.INVISIBLE : View.VISIBLE);
        //价格
        tv_wish_price.setText(item.getProduct_price());
        //创建时间
        tv_wish_createtime.setText(String.format(ResString.get(R.string.aaa4), item.getCreated_date()));

        helper.addOnClickListener(R.id.iv_wish_share);
        helper.addOnClickListener(R.id.ll_wish_delete);
//        helper.addOnClickListener(R.id.iv_wish_img);
        helper.addOnClickListener(R.id.iv_wish_shopcar);


    }
}
